package com.msg.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.msg.utils.ProjectConstants;
/**
 * This is generic Factory class that returns connection object
 * @author Shrikant.
 */	
public class DBConnectionFactory {
	Connection connection = null;
		
	public Connection getConnection() {
		try {
		 Class.forName("com.mysql.jdbc.Driver");
		 connection = DriverManager.getConnection(
				      ProjectConstants.DatabaseUrl, 
					  ProjectConstants.userName,
					  ProjectConstants.password);
		} 
		catch (ClassNotFoundException e) {
		 System.out.println("Include MySql JDBC Driver in your library path!");
		 e.printStackTrace();
		 return null;
		}
		catch (SQLException e) {
		System.out.println("Connection Failed! Check output console");
		e.printStackTrace();
		return null;
		}
	
		if (connection == null)
			System.out.println("Failed to make connection!");
		return connection;
		
	}

}
